package com.laint.hear.ui.base;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.laint.hear.R;
import com.laint.hear.adapter.BaseRecyclerViewViewHolder;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by leiyingtao on 2016/10/24.
 */

public abstract class BaseRecyclerViewListFragment<T> extends BaseFragment{
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    protected ArrayList<T> models = new ArrayList<>();

    @Override
    protected void setUpData() {
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setAdapter(new BaseRecyclerViewAdapter());
    }


    class BaseRecyclerViewAdapter extends RecyclerView.Adapter{

        @Override
        public int getItemCount() {
            return getDataCount();
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            ((BaseRecyclerViewViewHolder)holder).initData(position);
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return getViewHodler(parent,viewType);
        }
    }


    protected abstract RecyclerView.ViewHolder getViewHodler(ViewGroup parent, int viewType);
    protected abstract int getDataCount();


}
